package com.example.pet.controller;

import com.hj.pet.api.ShopService;
import com.hj.pet.model.ReturnT;
import com.hj.pet.model.Shop;
import org.elasticsearch.index.engine.Engine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.hj.pet.constant.Code.SUCCESS;

@RequestMapping("/internal/shop")
@RestController
public class shopController {
    @Autowired
    ShopService shopService;

    @RequestMapping(value = "/internal/shop/save",method = RequestMethod.POST)
    @ResponseBody
    public ReturnT<?> save(@RequestBody Shop shop){
        shopService.save(shop);
        return new ReturnT<>(SUCCESS, "success");
    }

    @RequestMapping(value = "updateByShopId",method = RequestMethod.POST)
    @ResponseBody
    public ReturnT<?> updateByShopId(@RequestBody Shop shop){
        shopService.updateByShopId(shop);
        return new ReturnT<>(SUCCESS,"success");
    }

    @RequestMapping(value = "findShopByShopId",method = RequestMethod.GET)
    @ResponseBody
    public ReturnT<?> findShopByShopId(@RequestParam String shop_id){
        Shop shop=shopService.findShopByShopId(shop_id);
        return new ReturnT<>(SUCCESS,shop);
    }

    @RequestMapping(value = "findShopByName",method = RequestMethod.GET)
    @ResponseBody
    public ReturnT<?> findShopByName(@RequestParam String shop_name){
        List<Shop> shops=shopService.findShopByName(shop_name);
        return new ReturnT<>(SUCCESS,shops);
    }

    @RequestMapping(value = "findShopByMaster",method = RequestMethod.GET)
    @ResponseBody
    public ReturnT<?> findShopByMaster(@RequestParam String master_id){
        List<Shop> shops=shopService.findShopByMaster(master_id);
        return new ReturnT<>(SUCCESS,shops);
    }

    @RequestMapping(value = "findShop",method = RequestMethod.GET)
    @ResponseBody
    public ReturnT<?> findShop(@RequestBody Shop shop){
        List<Shop> shops=shopService.findShop(shop);
        return new ReturnT<>(SUCCESS,shops);
    }

    @RequestMapping(value = "deleteById",method = RequestMethod.DELETE)
    @ResponseBody
    public ReturnT<?> deleteById(@RequestParam String shop_id){
        shopService.deleteById(shop_id);
        return new ReturnT<>(SUCCESS,"success");
    }

    @RequestMapping(value = "addShop",method = RequestMethod.POST)
    @ResponseBody
    public ReturnT<?> addShop(@RequestBody Shop shop){
        shopService.addShop(shop);
        return new ReturnT<>(SUCCESS,"success");
    }

    @RequestMapping(value = "update",method = RequestMethod.POST)
    @ResponseBody
    public ReturnT<?> update(Shop shop){
        shopService.update(shop);
        return new ReturnT<>(SUCCESS,"success");
    }

}
